﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using SX.BaseService.API.Base;
using SX.BaseService.Service;
using SX.Core;

namespace SX.BaseService.API
{
    [Menu]
    [Description("权限管理")]
    public class SysRolePermissionController : BaseController
    {
        private readonly ISysRolePermissionService _service;
        public SysRolePermissionController(ISysRolePermissionService sysRolePermissionService)
        {
            _service = sysRolePermissionService;
        }
        
        [HttpGet]
        [Description("查询角色权限")]
        public IApiResult GetPermission([FromQuery] string roleId )
        {
            return  _service.QueryPermission(roleId);
        }

        [HttpPost]
        [Description("授权")]
        public async Task<IApiResult> Add([FromBody] JObject obj)
        {
            JArray arr =obj.Value<JArray>("permissionIds");
            var list= arr.ToObject<List<string>>();
          
            return await _service.Add(list,obj.Value<string>("roleId"));
        }

        [HttpGet]
        [Description("查询角色列表")]
        public async Task<IApiResult> GetPermissionList()
        {
            return await _service.GetPermissionList();
        }
    }
}